package com.dongdongshop.controller;

import com.dongdongshop.common.AjaxResult;
import com.dongdongshop.mongopojo.Comment;
import com.dongdongshop.pojo.TbUser;
import com.dongdongshop.service.CommentService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("evaluate")
public class EvaluateController {
    @DubboReference
    private CommentService commentService;

    /*生成评论表*/
    @RequestMapping
    @ResponseBody
    public String criteriaComment(){
        commentService.criteriaComment();
        return "ok";
    }
    /*添加评论*/
    @RequestMapping("addEvaluate")
    @ResponseBody
    public AjaxResult addEvaluate(Comment comment){
        TbUser user = (TbUser) SecurityUtils.getSubject().getPrincipal();
        try {
            comment.setUserName(user.getUsername());
            commentService.addEvaluate(comment);
            return AjaxResult.OK();
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.ERROR();
        }
    }
}
